'''
Author: 火红色祥云 809880192@qq.com
Date: 2023-12-26 12:57:06
LastEditors: 火红色祥云 809880192@qq.com
LastEditTime: 2023-12-26 12:58:46
FilePath: /project_luckfox/pwm/pwm.py
Description: pwm demo
'''
from periphery import PWM
import time

pwm = PWM(10, 0)  

try:
    pwm.frequency = 1000
    pwm.duty_cycle = 0
    pwm.polarity = "normal"
    pwm.enable()

    direction = 1  

    while True:
        pwm.duty_cycle += 0.01 * direction
        pwm.duty_cycle = round(pwm.duty_cycle, 2)
        if pwm.duty_cycle == 1.0:
            direction = -1
        elif pwm.duty_cycle == 0.0:
            direction = 1
            
        time.sleep(0.05) 

except KeyboardInterrupt:
    pass

finally:
    pwm.close()
